import ChartDef from "@/views/modules/form/core/formComponent/ChartDef";
import {Util} from '@lowcode/jpaas-common-lib';
import MeasureSetting from "@/views/modules/form/core/chartDef/MeasureSetting.vue";
import SqlSetting from "@/views/modules/form/core/chartDef/SqlSetting";
import ColorSetting from "@/views/modules/form/core/chartDef/ColorSetting.vue";
import ColorSettings from "@/views/modules/form/core/chartDef/ColorSettings";
import IndicatorMax from "@/views/modules/form/core/chartDef/IndicatorMax";
import StyleSetting from "@/views/modules/form/core/chartDef/StyleSetting";
import DateSetting from "./DateSetting";

import {I18Parse} from '@lowcode/jpaas-common-lib';
import BasicsConfigJs from '../../../../../locales/lang/impl/form/BasicsConfigJsLang';
let lang = BasicsConfigJs;
let i18n=function (langKey,text) {
    return I18Parse.getI18Val(lang.BasicsConfigJs.title,langKey, text)
}
/**
 * 基础配置
 */
export default {
    name: "BasicsConfig",
    mixins: [ChartDef],
    props:{
        config:{
            type:Object
        }
    },
    data() {
        return {
            //不显示颜色图例的图表类型
            notShowLegend:['pie','gauge','funnel','map','numerical'],
            //不显示交互过滤条件的图表类型
            notShowFilter:['radar','map','numerical'],
        }
    },
    methods:{
        addMeasures(){
            this.config.measureList.push([]);
        },
        //度量配置
        setSetting(idx,index){
            var self=this;
            var baseConf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                zIndex: 9999,
                component: MeasureSetting,
                title: i18n('metric','度量配置'),
                shade:true,
                data:{
                    measure:this.config.measureList[idx][index]
                }
            };
            Util.open(baseConf, function (action,data) {
                if (action != 'ok') return;
                self.config.measureList[idx][index]=data;
                //手动触发config值变化
                self.$set(self.config,self.config);
            })
        },
        deletemeasure(index){
            this.config.measureList.splice(index,1);
        },
        setSql(fieldSetting){
            var self=this;
            var baseConf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                zIndex: 9999,
                component: SqlSetting,
                title: i18n('field','字段渲染'),
                shade:true,
                data:{
                    fieldSetting:fieldSetting
                }
            };
            Util.open(baseConf, function (action,sqlSetting) {
                if (action != 'ok') return;
                self.$set(fieldSetting,"sqlSetting",sqlSetting);
            })
        },
        setColor(fieldSetting,isLegend){
            var self=this;
            var baseConf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                zIndex: 9999,
                component:isLegend?ColorSettings:ColorSetting,
                title: i18n('color','颜色配置'),
                shade:true,
                data:{
                    fieldSetting:fieldSetting,
                    visualMap: this.config.visualMap
                }
            };
            Util.open(baseConf, function (action,data) {
                if (action != 'ok') return;
                self.$set(fieldSetting,"colorSetting",data);
            })
        },
        //设置指数
        setIndicatorMax(fieldSetting){
            var self=this;
            var baseConf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                zIndex: 9999,
                component:IndicatorMax,
                title: i18n('maximum','设置指数最大值'),
                shade:true,
                data:{
                    fieldSetting: fieldSetting
                }
            };
            Util.open(baseConf, function (action,data) {
                if (action != 'ok') return;
                self.$set(fieldSetting,"indicatorMax",data);
            })
        },
        setStyle(fieldSetting){
            var self=this;
            var baseConf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                zIndex: 9999,
                component:StyleSetting,
                title: i18n('style','样式配置'),
                shade:true,
                data:{
                    fieldSetting:fieldSetting
                }
            };
            Util.open(baseConf, function (action,data) {
                if (action != 'ok') return;
                self.$set(fieldSetting,"styleSetting",data);
            })
        },
        dateSetting(item,index){
            let self=this;
            Util.open({
                component: DateSetting,
                curVm: this,
                widthHeight: ['600px', '420px'],
                title: i18n('date','日期设置'),
                zIndex: 10000,
                data:{
                    dimension:item
                }
            }, function (action, data) {
                if (action != 'ok') return;
                self.$set(self.config.dimensions,index,data);
            });
        }
    }
}
